ConfigGrid = function(option){
	var title = option.title;
	var name = option.name;
	var this_grid = this;
	
	var sm = new Ext.grid.CheckboxSelectionModel({});
	
	var items = [{
				xtype : "textfield",
				fieldLabel : title,
				name : name+".name"
	}];
	var comps = option.comps?option.comps:[];
	for(var i=0;i<comps.length;i++){
		items.push(comps[i]);
	}
	
	var form = new Ext.form.FormPanel({
		autoHeight : true,
		frame : true,
		labelWidth : 70,
		items : [{
			xtype : "fieldset",
			padding : 5,
			title : "输入信息",
			defaults : {
				allowBlank : false,
				anchor : "95%"
			},
			items : items
		}]
	});
	
	var win = new Ext.Window({
		title : "添加"+title,
		width : 300,
		border : false,
		modal : true,
		closeAction : "hide",
		autoHeight : true,
		items : [form],
		buttons : [{
			text : "保存",
			handler : function(){
				if(!form.form.isValid()){
					return false;
				}
				Ajax({
					url : name+"/save.action",
					params : form.form.getFieldValues(),
					maskTarget : this_grid,
					window : win,
					grid : this_grid
				});
			}
		},{
			text : "取消",
			handler : function(){
				win.hide()
			}
		}],
		listeners : {
			hide : function(){
				form.form.reset();
			}
		}
	});
	
	
	var addButton = new Ext.Button({
		text : "添加",
		iconCls : "add",
		handler : function(){
			win.show();
		}
	});
	
	var remove = function(){
		var recs = this_grid.selModel.getSelections();
		if(recs.length==0) return;
		Ext.MessageBox.confirm("确认","确认删除"+title+"?",function(btn){
			if(btn == "yes"){
				var array = new Array();
				Ext.each(recs,function(rec,i){
					array.push(rec.get("id"));
				});
				var str = array.join(",");
				Ajax({
					url : name+"/delete.action",
					params : {"ids":str},
					maskTarget : this_grid,
					grid : this_grid
				});
			}
		});
	};
	
	var removeButton = new Ext.Button({
		text : "移除",
		iconCls : "delete",
		handler : remove
	});
	
	ConfigGrid.superclass.constructor.call(this, {
		title : title+"配置",
		height : 400,
		width : 280,
		autoExpandColumn : "name",
		hideHeaders : true,
		loadMask : true,
		sm : sm,
		collapsible : true,
		columns : option.columns,
		store : new Ext.data.JsonStore({
			url : name+"/query.action",
			fields : option.fields
		}),
		tbar : [addButton,removeButton]
	});
};
Ext.extend(ConfigGrid, Ext.grid.GridPanel);